<%@page import="doantotnghiep.modelDTO.MedicamentDTO"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.HashMap"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Thêm chi tiết nhập hàng</title>
</head>
<body>
	<% HashMap<String, Object> importedDetailModel = (HashMap<String, Object>) request.getAttribute("importedDetailModel");
	   float tong=0;
 		%>
	<div align="center">
		<h1 style="color: blue;">CHI TIẾT NHẬP HÀNG</h1>
		<form:form method="POST" commandName="ImportedDetailDTO">
			<tr>
			    <td><input type="text" style="font-size: 15px ;font-style: italic; color: silver;" 
			    placeholder="Nhập tên dược phẩm" id ="medicinekeyword" /></td>
			
				<td><span id="medicinesearchname-error" style="color:red;display: none;"> </span></td>
			
				<td><input type="button" id="medicinesearch" value="Tìm kiếm" /></td>
			</tr>
			<tr>
				<td><form:label path="medicamentID">Tên dược phẩm:</form:label></td>
				<td><form:select path="medicamentID" value="${medicamentID}">
						<%
			            if(importedDetailModel !=null){
   					    	 ArrayList<MedicamentDTO> medicamentDTOs =(ArrayList<MedicamentDTO>) importedDetailModel.get("medicamentDTOs");
   					   		 if(medicamentDTOs!=null){ 
   					         	for (int i = 0; i < medicamentDTOs.size(); i++) {			 
						   	 %>
						<option value="<%=medicamentDTOs.get(i).getId()%>"><%=medicamentDTOs.get(i).getMedicamentName()%></option>
						<%}}}%>
					</form:select></td>
			</tr>
			<tr>
				<td><form:label path="numberOfBatch">Số lượng lô:</form:label></td>
				<td><form:input id = "numberOfBatch" path="numberOfBatch" value="${numberOfBatch}"></form:input>
				<span id="numberOfBatch-error" style="color:red"> </span>
				</td>
			</tr>
			
			<tr>
				<td><input id="adddetailsubmit" type="button" value="Thêm" /></td>
			</tr>
		</form:form>
		 <div id="purchasedetail" align="center">
			<table class="table1" id="importeddetailtable">
				<tr>
					
					<th scope="col" abbr="Starter">Mã dược phẩm</th>
					<th scope="col" abbr="Starter">Tên dược phẩm</th>
					<th scope="col" abbr="Starter">Sô lượng lô</th>
					<th scope="col" abbr="Starter">Thành tiền</th>
				</tr>
			    
				 <c:forEach items="${importedDetailModel.importedDetailDTOs}" var="detail"
							varStatus="status">
				<c:if test="detail!=null">
							<tr class="<c:if test="${status.count % 2 == 0}">even</c:if>">
				<tr>
					<td>${detail.medicamentID}</td>
					<td>${detail.medicamentName}</td>
					<td>${detail.numberOfBatch}</td>
					<td>${detail.importCost}</td>
					
					<td><a href="#"> <img
							src="<c:url value="/resources/images/edit-icon.png"/>" /></a></td>
					<td><a href="#"> <img
							src="<c:url value="/resources/images/delete-icon1.png"/>" /></a></td>
				</tr>
				</c:if>
				</c:forEach> 
				
			</table>
			
			<div id="importdetailpaging"></div>
			
			 <script type="text/javascript">
						var pager = new Pager('importeddetailtable', 5);
						pager.init();
						pager.showPageNav('pager', 'importdetailpaging');
						pager.showPage(1);
			</script> 
			<br><br>
			<input id= "addimportedsubmit" type="button" value="Hoàn tất" />
				<input id= "addimportedcancel" type="button" value="Hủy" />
					
			</div> 
	</div>
</body>
</html>